package com.igeek.d0531;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Author: zhiyu
 * @Date:15:56
 * @DESC:
 */
public class UserTest {
    public static void main(String[] args) {
        selectUser(getUser());
    }
    public static ArrayList<User> getUser(){
        User user1 = new User("a", 23);
        User user2 = new User("b", 22);
        User user3 = new User("c", 21);
        User user4 = new User("d", 20);
        User user5 = new User("e", 19);
        ArrayList<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);
        users.add(user5);
        return users;
    }
    public static boolean selectUser(ArrayList<User> users){
        Scanner scanner = new Scanner(System.in);
        for (int j = 0; j < 3; j++) {
            System.out.println("请输入你要查询的姓名：");
            String name = scanner.nextLine();
            scanner.nextLine();
            System.out.println("请输入年龄：");
            int age = scanner.nextInt();
            for (int i = 0; i < users.size(); i++) {
                if (name.equals(users.get(i).getName())){
                    if (users.get(i).getAge().equals(age)){
                        System.out.println("登录成功");
                        return true;
                    }
                }
            }
        }
        System.out.println("登录失败");
        return false;
    }
}
